#!/bin/sh
# sh cycle_add_partition.sh target_absTable source_absTable 20180701 20170801
target_absTable=$1
source_absTable=$2
if [[ $# == 4 ]]; then
    begin_date=$3
    end_date=$4
    date=${begin_date}
    while [[ "${date}" -le "${end_date}" ]]
    do
      sql="insert into ${target_absTable} partition(data_date=${date}) select * from ${source_absTable} distribute by rand() limit 10000"
      echo ${sql}
      beeline -u "jdbc:hive2://172.18.33.23:10000" -n spark -e "${sql}"
      date=`date -d "$date 1 days" +"%Y%m%d"`
    done
else
    echo 'Parameter error!'
fi